﻿namespace AnyOffice.DAL
{
    using AnyOffice.Model;
    using Microsoft.ApplicationBlocks.Data;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class InterfaceDao
    {
        public DataTable SelectAll(SqlConnection conn)
        {
            string commandText = "SELECT * FROM [dbo].[Interface]";
            DataSet set = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText);
            set.Tables[0].TableName = "Interface";
            return set.Tables[0];
        }

        public bool Update(SqlConnection conn, InterfaceData data)
        {
            string commandText = "UPDATE [dbo].[Interface] SET [IeTitle] = @IeTitle, [Statustext] = @Statustext, [Bannertext] = @Bannertext, [BannerFont] = @BannerFont, [LogoWidth] = @LogoWidth, [LogoHeight] = @LogoHeight";
            SqlParameter[] commandParameters = new SqlParameter[6];
            commandParameters[0] = new SqlParameter("@IeTitle", SqlDbType.NVarChar, 200);
            commandParameters[0].Value = data.IeTitle;
            commandParameters[1] = new SqlParameter("@StatusText", SqlDbType.NVarChar, 200);
            commandParameters[1].Value = data.StatusText;
            commandParameters[2] = new SqlParameter("@BannerText", SqlDbType.NVarChar, 200);
            commandParameters[2].Value = data.BannerText;
            commandParameters[3] = new SqlParameter("@BannerFont", SqlDbType.NVarChar, 200);
            commandParameters[3].Value = data.BannerFont;
            commandParameters[4] = new SqlParameter("@LogoWidth", SqlDbType.Int);
            commandParameters[4].Value = data.LogoWidth;
            commandParameters[5] = new SqlParameter("@LogoHeight", SqlDbType.Int);
            commandParameters[5].Value = data.LogoHeight;
            SqlHelper.ExecuteNonQuery(conn, CommandType.Text, commandText, commandParameters);
            return true;
        }
    }
}

